package com.cecil.generate.model;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.List;

@Data
@EqualsAndHashCode(callSuper = true)
public class PageParam<T> extends Page<T> {

    private List<Param> params;

    @Data
    public static class Param {
        /**
         * 请求参数
         */
        private String column;
        /**
         * 请求类型
         */
        private String searchType;
        /**
         * 参数值，一个
         */
        private Object value;
        /**
         * 参数值，多个
         */
        private Object[] values;
    }

    public QueryWrapper<T> buildWrapper() {
        QueryWrapper<T> queryWrapper = new QueryWrapper<>();
        if (null == params || params.isEmpty()) {
            return queryWrapper;
        }
        PageParamSearchTypeEnum.buildWrapper(queryWrapper, params);
        return queryWrapper;
    }
}
